package com.syyo.gulimall.order.controller;

//import org.springframework.security.access.prepost.PreAuthorize;
import com.syyo.common.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.syyo.gulimall.order.domain.req.OrderReq;
import com.syyo.gulimall.order.service.OrderService;
import com.syyo.common.domain.ResultVo;

import java.util.Map;


/**
 * 订单
 *
 * @author syyo
 * @email syyo@gmail.com
 * @date 2021-01-20 10:01:14
 */
@RestController
@RequestMapping("/order/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
    * 新增
    */
    @PostMapping
    // @PreAuthorize("@syyo.check('system:order:add')")
    public ResultVo add(@RequestBody OrderReq req){
        return ResultUtils.ok(orderService.add(req));
    }

    /**
 * 删除
 */
    @DeleteMapping("/{id}")
    // @PreAuthorize("@syyo.check('system:order:del')")
    public ResultVo del(@PathVariable("id") Integer id){
        return ResultUtils.ok(orderService.del(id));
    }

    /**
   * 修改
   */
    @PutMapping
    // @PreAuthorize("@syyo.check('system:order:edit')")
    public ResultVo edit(@RequestBody OrderReq req){
        return ResultUtils.ok(orderService.edit(req));
    }

    /**
     * 信息
     */
    @GetMapping("/{id}")
    public ResultVo findOne(@PathVariable("id") Integer id){
        return ResultUtils.ok(orderService.findOne(id));
    }

    /**
      * 列表
      */
    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResultVo findAll(@PathVariable("pageNum") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize,
                            OrderReq req){
        return ResultUtils.ok(orderService.findAll(pageNum,pageSize,req));
    }

    /**
     * 信息
     */
    @GetMapping("/status/{orderSn}")
    public ResultVo getOrderStatus(@PathVariable("orderSn") String orderSn){
        return ResultUtils.ok(orderService.getOrderStatus(orderSn));
    }

    /**
     * 列表
     */
    @PostMapping("/listWithItem/{pageNum}/{pageSize}")
    public ResultVo listWithItem(@PathVariable("pageNum") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize,
                            @RequestBody Map<String,Object> params){
        return ResultUtils.ok(orderService.listWithItem(pageNum,pageSize,params));
    }
}
